package com.shpng.cheapenglish.persistent;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.shpng.cheapenglish.db.UserUnit;

public class UserUnitPersistent {

	private static UserUnitPersistent UserUnitPersistent;

	private UserUnitPersistent() {

	}

	public static UserUnitPersistent getInstance() {
		if (UserUnitPersistent == null)
			UserUnitPersistent = new UserUnitPersistent();
		return UserUnitPersistent;
	}

	@SuppressWarnings("unchecked")
	public List<UserUnit> getUserUnits(PersistenceManager pm) {
		Query query = pm.newQuery(UserUnit.class);
		List<UserUnit> userUnits = (List<UserUnit>) query.execute();
		return userUnits;

	}

	public void saveUserUnit(PersistenceManager pm, UserUnit userUnit) {
		pm.makePersistent(userUnit);
		System.out.println("save unit " + userUnit.getUnit());
	}

}
